<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/6/7
  Time: 7:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/ucenter/addrManager.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body>
<jsp:include page="../public/header.jsp" flush="true" />
<a href="/ucenter/addAddress.do?target=\/ucenter\/myAddress.do">
<div class="home-nav-down">
    <p><i class="iconfont icon-shouye icon">&#xe60d;</i>添加新地址</p>
</div></a>
<section>
    <div class="my_addrMa">
        <c:forEach items="${addresses}" var="item" varStatus="statu">
            <div class="cont ">
                <div class="tit"><span class="s1">${item.consignee}</span><span class="s2">${item.phone}</span></div>
                <div class="txt">${item.address}</div>
                <div class="info">
                    <input type="checkbox" class="i_radio" <c:if test="${item.isDefault == 'y'}" >checked="true"</c:if> onclick="setDefault(${item.id},${statu.index})" id="c${statu.index}">
                    <div class="in_left">
                        <i class="iconfont s1">&#xe61c;</i><span class="s2">设为默认</span></div>
                    <div class="in_right">
                        <a href="/ucenter/addAddress.do?id=${item.id}&target=\/ucenter\/myAddress.do"> <i class="iconfont s1">&#xe608;</i><span class="s2">编辑</span></a>
                        <a onclick="del(${item.id})"> <i class="iconfont s3">&#xe60b;</i><span class="s4">删除</span></a></div>
                    </div>
            </div>
        </c:forEach>
    </div>
</section>
<script>
    function del(id) {
        if (!confirm("是否删除")){
            return;
        }
        $.get("/mobile/user/address?action=delete&accountId=${userinfo.id}&id="+id,function (data) {
            if (!data.success){
                tip("",data.msg,true);
            }else {
                window.location.reload();
            }
        },"json");
    }
    function setDefault(id,index) {
//        $("input[type='checkbox']").checked(false);
//        $("input[type='checkbox']").attr("checked",false);
//        $("#c"+index).attr("checked",true);

        $.get("/mobile/user/address?action=setDefault&accountId=${userinfo.id}&id="+id,function (data) {
            if (!data.success){
                tip("",data.msg,true);
            }else {
                window.location.reload();
            }
        },"json");
    }
</script>
<footer>
    <div  class="my_ocupie"></div>
</footer>
</body>
</html>
